#include "tagaxis.h"

TagAxis::TagAxis(QCPAxis *parentAxis) : QObject(parentAxis),
    mAxis(parentAxis)
{
    mDummyTracerY1 = new QCPItemTracer(mAxis->parentPlot());
    mDummyTracerY1->setVisible(true);
    mDummyTracerY1->position->setTypeX(QCPItemPosition::ptAxisRectRatio);//QCPItemPosition::ptPlotCoords
    mDummyTracerY1->position->setTypeY(QCPItemPosition::ptPlotCoords);
    mDummyTracerY1->position->setAxisRect(mAxis->axisRect());
    mDummyTracerY1->position->setAxes(0, mAxis);

    mLabelY1 = new QCPItemText(mAxis->parentPlot());
    mLabelY1->setLayer("overlay");
    mLabelY1->setClipToAxisRect(false);
    mLabelY1->setPadding(QMargins(3, 0, 3, 0));
    mLabelY1->setBrush(QBrush(Qt::white));
    mLabelY1->setPen(QPen(Qt::blue));
    mLabelY1->setPositionAlignment(Qt::AlignRight|Qt::AlignVCenter);
    mLabelY1->position->setTypeX(QCPItemPosition::ptAxisRectRatio);//QCPItemPosition::ptPlotCoords
    mLabelY1->position->setTypeY(QCPItemPosition::ptPlotCoords);


}
TagAxis::~TagAxis()
{
    if (mDummyTracerY1)
        mDummyTracerY1->parentPlot()->removeItem(mDummyTracerY1);
    if (mLabelY1)
        mLabelY1->parentPlot()->removeItem(mLabelY1);


}

void TagAxis::setPen(const QPen &pen)
{
  mLabelY1->setPen(pen);

}

void TagAxis::setBrush(const QBrush &brush)
{
  mLabelY1->setBrush(brush);

}

void TagAxis::setTextY1(const QString &text)
{
  mLabelY1->setText(text);
}



void TagAxis::updatePosition(double valueY1)
{
    mDummyTracerY1->position->setCoords(0, valueY1);
    mLabelY1->position->setCoords(0,valueY1);


}
